/** 
* @author xiaoshan E-mail: xiaoshan2242@gmail.com
* @version 0.00.01 ����ʱ�䣺Sep 19, 2008 10:27:09 AM 
* ��˵�� 
*/ 

package com.walllee.core.util.json; 

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

public class TimeStampJsonValueProcessorImpl implements JsonValueProcessor {
	private String format = "yyyy-MM-dd";

	public TimeStampJsonValueProcessorImpl() {
	}

	public TimeStampJsonValueProcessorImpl(String format) {
		this.format = format;
	}

	public Object processArrayValue(Object value, JsonConfig jsonConfig) {
		String[] obj = {};
		if (value instanceof Timestamp[]) {
			SimpleDateFormat sf = new SimpleDateFormat(format);
			Timestamp[] dates = (Timestamp[]) value;
			obj = new String[dates.length];
			for (int i = 0; i < dates.length; i++) {
				obj[i] = sf.format(dates[i]);
			}
		}
		return obj;
	}

	public Object processObjectValue(String arg0, Object value, JsonConfig arg2) {
		if (value instanceof Timestamp) {
			String str = new SimpleDateFormat(format).format((Timestamp) value);
			return str;
		}
		return value.toString();
	}

}
 